<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Keyword List Operator</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../../../index.html" title="Spirit Repository 0.2">
<link rel="up" href="../operators.html" title="Qi Parser Operators">
<link rel="prev" href="../operators.html" title="Qi Parser Operators">
<link rel="next" href="../../karma_components.html" title="Karma Components">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../operators.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operators.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../karma_components.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="spirit_repository.qi_components.operators.keyword_list"></a><a class="link" href="keyword_list.html" title="Keyword List Operator">Keyword
        List Operator</a>
</h4></div></div></div>
<h6>
<a name="spirit_repository.qi_components.operators.keyword_list.h0"></a>
          <span class="phrase"><a name="spirit_repository.qi_components.operators.keyword_list.description"></a></span><a class="link" href="keyword_list.html#spirit_repository.qi_components.operators.keyword_list.description">Description</a>
        </h6>
<p>
          The keyword list operator, <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="string">"k1"</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span>
          <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="string">"k2"</span><span class="special">)[</span><span class="identifier">b</span><span class="special">]</span></code>,
          works tightly with the kwd, ikwd, dkwd and idkwd directives to effeciently
          match keyword lists. As long as one of the keywords specified through the
          kwd, ikwd, dkwd or idkwd directive matches, the keyword will be immediatly
          followed by the keyword's associated subject parser. The parser will continue
          parsing input as long as the one of the keywords and it's associated parser
          succeed. Writing : (kwd("k1")[a] / kwd("k2")[b] / ...
          ) is equivalent to: *( "k1" &gt; a | "k2" &gt; b ...
          ).
        </p>
<h6>
<a name="spirit_repository.qi_components.operators.keyword_list.h1"></a>
          <span class="phrase"><a name="spirit_repository.qi_components.operators.keyword_list.header"></a></span><a class="link" href="keyword_list.html#spirit_repository.qi_components.operators.keyword_list.header">Header</a>
        </h6>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/repository/home/qi/operator/keywords.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">repository</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_keywords</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<h6>
<a name="spirit_repository.qi_components.operators.keyword_list.h2"></a>
          <span class="phrase"><a name="spirit_repository.qi_components.operators.keyword_list.expression_semantics"></a></span><a class="link" href="keyword_list.html#spirit_repository.qi_components.operators.keyword_list.expression_semantics">Expression
          Semantics</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Expression
                  </p>
                </th>
<th>
                  <p>
                    Semantics
                  </p>
                </th>
</tr></thead>
<tbody><tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span>
                    <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k2</span><span class="special">)[</span><span class="identifier">b</span><span class="special">]</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Match <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)</span>
                    <span class="special">&gt;</span> <span class="identifier">a</span></code>
                    or <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">k2</span><span class="special">)</span>
                    <span class="special">&gt;</span> <span class="identifier">b</span></code>,
                    equivalent to <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)</span> <span class="special">&gt;</span>
                    <span class="identifier">a</span> <span class="special">|</span>
                    <span class="identifier">lit</span><span class="special">(</span><span class="identifier">k2</span><span class="special">)</span>
                    <span class="special">&gt;</span> <span class="identifier">b</span></code>
                  </p>
                </td>
</tr></tbody>
</table></div>
<h6>
<a name="spirit_repository.qi_components.operators.keyword_list.h3"></a>
          <span class="phrase"><a name="spirit_repository.qi_components.operators.keyword_list.attributes"></a></span><a class="link" href="keyword_list.html#spirit_repository.qi_components.operators.keyword_list.attributes">Attributes</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Expression
                  </p>
                </th>
<th>
                  <p>
                    Attribute
                  </p>
                </th>
</tr></thead>
<tbody><tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="string">"k1"</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span>
                    <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="string">"k2"</span><span class="special">)[</span><span class="identifier">b</span><span class="special">]</span></code>
                  </p>
                </td>
<td>
                  <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span> <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k2</span><span class="special">)[</span><span class="identifier">b</span><span class="special">]):</span> <span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">B</span><span class="special">&gt;</span>
<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span> <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k2</span><span class="special">)[</span><span class="identifier">b</span><span class="special">]):</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">kwd</span><span class="special">(</span><span class="string">"k1"</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span> <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k2</span><span class="special">)[</span><span class="identifier">b</span><span class="special">]):</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">B</span><span class="special">&gt;</span>
<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span> <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k2</span><span class="special">)[</span><span class="identifier">b</span><span class="special">]):</span> <span class="identifier">Unused</span>

<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;(</span><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span> <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k2</span><span class="special">)[</span><span class="identifier">b</span><span class="special">]):</span> <span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">A</span><span class="special">&gt;</span></pre>
<p>
                  </p>
                </td>
</tr></tbody>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
            The keyword list parser works tightly with the kwd, ikwd, dkwd and idkwd
            directives and can't be used without it. A compile time error will warn
            you of any mistakes. This parser collects all the kwd directives and
            extracts the keyword literals or parsers from the directives to internaly
            build a Ternary Search Tree (TST) and permutation loop (for complex parsers)
            to effectively parse the keywords. Because you can't mix character types
            inside a TST you must take care not to mix wide strings with normal strings
            in the keywords you supply to a keyword list. Should it happen the compiler
            will trap the mistake for you.
          </p></td></tr>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
            The kwd directive also works a bit like the repeat directive and can
            be used to formulate additional contraints on the number of times a keyword
            can or must occur while parsing a keyword list.
          </p></td></tr>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
            The kwd, dkwd and ikwd, idkwd directives can be mixed inside a keyword
            list. This has however a small overhead and should be avoided when possible.
          </p></td></tr>
</table></div>
<h6>
<a name="spirit_repository.qi_components.operators.keyword_list.h4"></a>
          <span class="phrase"><a name="spirit_repository.qi_components.operators.keyword_list.complexity"></a></span><a class="link" href="keyword_list.html#spirit_repository.qi_components.operators.keyword_list.complexity">Complexity</a>
        </h6>
<div class="blockquote"><blockquote class="blockquote"><p>
            The overall complexity of the keyword list parser is defined by the sum
            of the complexities of its elements.
          </p></blockquote></div>
<h6>
<a name="spirit_repository.qi_components.operators.keyword_list.h5"></a>
          <span class="phrase"><a name="spirit_repository.qi_components.operators.keyword_list.example"></a></span><a class="link" href="keyword_list.html#spirit_repository.qi_components.operators.keyword_list.example">Example</a>
        </h6>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
            The test harness for the example(s) below is presented in the <a href="../../../../../../doc/html/spirit/qi/reference/basics.html#spirit.qi.reference.basics.examples" target="_top">Basics
            Examples</a> section.
          </p></td></tr>
</table></div>
<p>
          Declare a small data structure representing a person:
        </p>
<p>
</p>
<pre class="programlisting"><span class="comment">// Data structure definitions to test the kwd directive</span>
<span class="comment">// and the keywords list operator</span>

<span class="keyword">struct</span> <span class="identifier">person</span> <span class="special">{</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">name</span><span class="special">;</span>
    <span class="keyword">int</span> <span class="identifier">age</span><span class="special">;</span>
    <span class="keyword">double</span> <span class="identifier">size</span><span class="special">;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;</span> <span class="identifier">favorite_colors</span><span class="special">;</span>

<span class="special">};</span>

<span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span> <span class="special">&amp;</span><span class="keyword">operator</span><span class="special">&lt;&lt;(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span> <span class="special">&amp;</span><span class="identifier">os</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">person</span> <span class="special">&amp;</span><span class="identifier">p</span><span class="special">)</span>
<span class="special">{</span>
    <span class="identifier">os</span><span class="special">&lt;&lt;</span><span class="string">"Person : "</span><span class="special">&lt;&lt;</span><span class="identifier">p</span><span class="special">.</span><span class="identifier">name</span><span class="special">&lt;&lt;</span><span class="string">", "</span><span class="special">&lt;&lt;</span><span class="identifier">p</span><span class="special">.</span><span class="identifier">age</span><span class="special">&lt;&lt;</span><span class="string">", "</span><span class="special">&lt;&lt;</span><span class="identifier">p</span><span class="special">.</span><span class="identifier">size</span><span class="special">&lt;&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">copy</span><span class="special">(</span><span class="identifier">p</span><span class="special">.</span><span class="identifier">favorite_colors</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span><span class="identifier">p</span><span class="special">.</span><span class="identifier">favorite_colors</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream_iterator</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;(</span><span class="identifier">os</span><span class="special">,</span><span class="string">"\n"</span><span class="special">));</span>
    <span class="keyword">return</span> <span class="identifier">os</span><span class="special">;</span>
<span class="special">}</span>

<span class="identifier">BOOST_FUSION_ADAPT_STRUCT</span><span class="special">(</span> <span class="identifier">person</span><span class="special">,</span>
    <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">name</span><span class="special">)</span>
    <span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">age</span><span class="special">)</span>
    <span class="special">(</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">size</span><span class="special">)</span>
    <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;,</span> <span class="identifier">favorite_colors</span><span class="special">)</span>
<span class="special">)</span>
</pre>
<p>
        </p>
<p>
          Some using declarations:
        </p>
<p>
</p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">repository</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">kwd</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">inf</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">space_type</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">double_</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">int_</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">rule</span><span class="special">;</span>
</pre>
<p>
        </p>
<p>
          Now let's declare a keyword parser:
        </p>
<p>
</p>
<pre class="programlisting"><span class="identifier">no_constraint_person_rule</span> <span class="special">%=</span>
    <span class="identifier">kwd</span><span class="special">(</span><span class="string">"name"</span><span class="special">)[</span><span class="char">'='</span> <span class="special">&gt;</span> <span class="identifier">parse_string</span> <span class="special">]</span>
  <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="string">"age"</span><span class="special">)</span>   <span class="special">[</span><span class="char">'='</span> <span class="special">&gt;</span> <span class="identifier">int_</span><span class="special">]</span>
  <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="string">"size"</span><span class="special">)</span>   <span class="special">[</span><span class="char">'='</span> <span class="special">&gt;</span> <span class="identifier">double_</span> <span class="special">&gt;</span> <span class="char">'m'</span><span class="special">]</span>
  <span class="special">;</span>
</pre>
<p>
        </p>
<p>
          A couple of input string variations run on the same parser:
        </p>
<p>
          Parsing a keyword list:
        </p>
<p>
</p>
<pre class="programlisting"><span class="comment">// Let's declare a small list of people for which we want to collect information.</span>
<span class="identifier">person</span> <span class="identifier">John</span><span class="special">,</span><span class="identifier">Mary</span><span class="special">,</span><span class="identifier">Mike</span><span class="special">,</span><span class="identifier">Hellen</span><span class="special">,</span><span class="identifier">Johny</span><span class="special">;</span>
<span class="identifier">test_phrase_parser_attr</span><span class="special">(</span>
                <span class="string">"name = \"John\" \n age = 10 \n size = 1.69m "</span>
                <span class="special">,</span><span class="identifier">no_constraint_person_rule</span>
                <span class="special">,</span><span class="identifier">John</span><span class="special">);</span>  <span class="comment">// full in orginal order</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">&lt;&lt;</span><span class="identifier">John</span><span class="special">;</span>

<span class="identifier">test_phrase_parser_attr</span><span class="special">(</span>
                <span class="string">"age = 10 \n size = 1.69m \n name = \"Mary\""</span>
                <span class="special">,</span><span class="identifier">no_constraint_person_rule</span>
                <span class="special">,</span><span class="identifier">Mary</span><span class="special">);</span>  <span class="comment">// keyword oder doesn't matter</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">&lt;&lt;</span><span class="identifier">Mary</span><span class="special">;</span>

<span class="identifier">test_phrase_parser_attr</span><span class="special">(</span>
                 <span class="string">"size = 1.69m \n name = \"Mike\" \n age = 10 "</span>
                <span class="special">,</span><span class="identifier">no_constraint_person_rule</span>
                <span class="special">,</span><span class="identifier">Mike</span><span class="special">);</span>  <span class="comment">// still the same result</span>

<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">&lt;&lt;</span><span class="identifier">Mike</span><span class="special">;</span>
</pre>
<p>
        </p>
<p>
          The code above will print:
        </p>
<pre class="programlisting">Person : John, 10, 1.69
Person : Mary, 10, 1.69
Person : Mike, 10, 1.69
</pre>
<p>
          Now let's delcare a parser with some occurrence constraints:
        </p>
<p>
          The parser definition below uses the kwd directive occurrence constraint
          variants to make sure that the name and age keyword occur only once and
          allows the favorite color entry to appear 0 or more times.
        </p>
<p>
</p>
<pre class="programlisting"><span class="identifier">constraint_person_rule</span> <span class="special">%=</span>
    <span class="identifier">kwd</span><span class="special">(</span><span class="string">"name"</span><span class="special">,</span><span class="number">1</span><span class="special">)</span>                 <span class="special">[</span><span class="char">'='</span> <span class="special">&gt;</span> <span class="identifier">parse_string</span> <span class="special">]</span>
  <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="string">"age"</span>   <span class="special">,</span><span class="number">1</span><span class="special">)</span>                 <span class="special">[</span><span class="char">'='</span> <span class="special">&gt;</span> <span class="identifier">int_</span><span class="special">]</span>
  <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="string">"size"</span>   <span class="special">,</span><span class="number">1</span><span class="special">)</span>                 <span class="special">[</span><span class="char">'='</span> <span class="special">&gt;</span> <span class="identifier">double_</span> <span class="special">&gt;</span> <span class="char">'m'</span><span class="special">]</span>
  <span class="special">/</span> <span class="identifier">kwd</span><span class="special">(</span><span class="string">"favorite color"</span><span class="special">,</span><span class="number">0</span><span class="special">,</span><span class="identifier">inf</span><span class="special">)</span> <span class="special">[</span> <span class="char">'='</span> <span class="special">&gt;</span> <span class="identifier">parse_string</span> <span class="special">]</span>
  <span class="special">;</span>
</pre>
<p>
        </p>
<p>
          And see how it works in these two cases:
        </p>
<p>
</p>
<pre class="programlisting"> <span class="comment">// Here all the give constraint are resepected : parsing will succeed.</span>
 <span class="identifier">test_phrase_parser_attr</span><span class="special">(</span>
     <span class="string">"name = \"Hellen\" \n age = 10 \n size = 1.80m \n favorite color = \"blue\" \n favorite color = \"green\" "</span>
     <span class="special">,</span><span class="identifier">constraint_person_rule</span>
     <span class="special">,</span><span class="identifier">Hellen</span><span class="special">);</span>
 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">&lt;&lt;</span><span class="identifier">Hellen</span><span class="special">;</span>

<span class="comment">// Parsing this string will fail because the age and size minimum occurrence requirements aren't met.</span>
<span class="identifier">test_phrase_parser_attr</span><span class="special">(</span>
     <span class="string">"name = \"Johny\"  \n favorite color = \"blue\" \n favorite color = \"green\" "</span>
     <span class="special">,</span><span class="identifier">constraint_person_rule</span>
     <span class="special">,</span><span class="identifier">Johny</span> <span class="special">);</span>
</pre>
<p>
        </p>
<p>
          Parsing the first string will succeed but fail for the second string as
          the occurrence constraints aren't met. This code should print:
        </p>
<pre class="programlisting">Person : Hellen, 10, 1.8
blue
green
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../operators.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operators.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../karma_components.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
